package com.dg11185.nearshop.db.entity;

import android.os.Parcel;
import android.os.Parcelable;

import com.dg11185.libs.ormlite.field.DatabaseField;
import com.dg11185.libs.ormlite.table.DatabaseTable;
import com.dg11185.nearshop.net.entity.MerchantInfo;

/**
 * 保存用户浏览记录表
 * 
 * @author：Daibo
 * @time：2014-6-29 下午4:33:34
 */
@DatabaseTable(tableName = DbConstant.MERCHANT)
public class Merchant implements Parcelable {

    @DatabaseField(generatedId = true)
    private int id;

    @DatabaseField(width = 10)
    public String merchantId = "";

    @DatabaseField(width = 20)
    public String merchantName = "";

    @DatabaseField(width = 20)
    public String areaName = "";

    @DatabaseField(width = 20)
    public String industryName = "";

    @DatabaseField(width = 20)
    public String longitude = "";

    @DatabaseField(width = 20)
    public String latitude = "";

    @DatabaseField(width = 10)
    public String discount = "";

    @DatabaseField(width = 10)
    public String avgRating = "";

    @DatabaseField()
    public String midPhotoUrl = "";

    public Merchant() {

    }    
    
    /**
     * 
     * 创建一个新的实例 Merchant.    
     *    
     * @param info
     */
    public Merchant(MerchantInfo info) {
        merchantId = info.merchantId;
        merchantName = info.merchantName;
        latitude = info.latitude;
        longitude = info.longitude;
        discount = info.discountMsg;
        avgRating = info.avgRating;
        midPhotoUrl = info.midPhotoUrl;
    }

    public Merchant(Parcel in) {
        String[] data = new String[9];
        in.readStringArray(data);
        this.merchantId = data[0];
        this.merchantName = data[1];
        this.areaName = data[2];
        this.industryName = data[3];
        this.longitude = data[4];
        this.latitude = data[5];
        this.discount = data[6];
        this.avgRating = data[7];
        this.midPhotoUrl = data[8];
    }

    public static final Parcelable.Creator<Merchant> CREATOR = new Creator<Merchant>() {

        @Override
        public Merchant createFromParcel(Parcel source) {
            return new Merchant(source);
        }

        @Override
        public Merchant[] newArray(int size) {
            return new Merchant[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeStringArray(new String[] { this.merchantId, this.merchantName, this.areaName, this.industryName,
                this.longitude, this.latitude, this.discount, this.avgRating, this.midPhotoUrl });
    }
}
